package com.shg.web.ztest;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.shg.bean.BuyCart;
import com.shg.bean.BuyItem;
import com.shg.bean.Users;
import com.shg.service.BuyCartService;

public class BuyCartServiceTest {

	static BuyCartService buyCartService;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		ApplicationContext context=new ClassPathXmlApplicationContext("basics-application.xml");
		buyCartService =(BuyCartService)context.getBean("buyCartServiceBean");
	}

	@Test
	public void testInsert() {
		BuyCart entity=new BuyCart();
		
		BuyItem item=new BuyItem();
		item.setId("297ec07636e242200136e24a62d60003");
		item.setCount(1);
		
		BuyItem item2=new BuyItem();
		item2.setId("297ec07636e242200136e248c8d30002");
		item2.setCount(1);
		
		entity.addItem(item);
		entity.addItem(item2);
		
		Users users=new Users();
		users.setId("402890ba383ae36701383b032e900009");
		entity.setUser(users);
		
		buyCartService.insert(entity);
	}
	
	@Test
	public void testList(){
		BuyCart buyCart=null;
		try {
			buyCart = (BuyCart) buyCartService.select(BuyCart.class, "402890ba383ae36701383b032e900009");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(buyCart!=null){
			List<BuyItem> list = buyCart.getItems();
			for(BuyItem item:list){
				System.out.println(item.getId()+"  "+item.getCount());
			}
		}
	}

}
